package leetcode.l0526;

import java.util.ArrayList;
import java.util.HashSet;

/**
 * @author Retain
 * @date 2021/5/26 22:29
 */
public class Easy_环形链表_141 {
    public boolean hasCycle(ListNode head) {
        if (head == null || head.next == null) {
            return false;
        }
        ListNode slow = head;
        ListNode fast = head.next;
       while (slow != fast) {
           if (slow == null || fast == null) {
               return false;
           }
        slow = slow.next;
        fast = fast.next.next;
       }
       return true;
    }


    static class ListNode {
        int val;
        ListNode next;
        ListNode(int x) {
            val = x;
            next = null;
        }
    }

}
